#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int dx[N],vv[N],d[N],a[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    scanf("%d",&t);
    int ans=0;
    for(int i=1;i<=t;i++){
		ans=0;
		int n,m,l,v;
		scanf("%d%d%d%d",&n,&m,&l,&v);
		for(int j=1;j<=n;j++){
			cin>>d[j]>>vv[j]>>a[j];
		}
		for(int k=1;k<=m;k++){
			cin>>dx[k];
		}
		sort(dx+1,dx+m+1);
		for(int j=1;j<=n;j++){
			if(vv[j]>v and d[j]<=dx[m]) ans++;
		}
		if(ans!=0) cout<<ans<<' '<<m-1<<endl;
		if(ans==0) cout<<ans<<' '<<m<<endl;
	}
	return 0;
}
